// 用于存储每个请求的标识和取消函数
const pendingMap = new Map<string, AbortController>()
// 添加等待中的请求数据
function addPending(url: string) {
	const controller = new AbortController()
	const signal = controller.signal
	pendingMap.set(url, controller)
	return signal
}
// 删除等待中的请求数据
function removePending(url: string) {
	pendingMap.delete(url)
}
function cancelRequest(url: string) {
	if (pendingMap.has(url)) {
		const cancel = pendingMap.get(url)
		cancel?.abort()
		pendingMap.delete(url)
	}
}
// 删除所有等待中的请求数据
function removeAllPending() {
	pendingMap.forEach((abortController) => abortController.abort())
}
export { addPending, cancelRequest, removePending, removeAllPending }
